

/**
 * 设置某个元素的显示/隐藏
 * @param {*} element 
 * @param {boolean} visiable 
 */
export const setElementVisiblity = (element, visiable) => {
    if (visiable) element.show();
    else element.hide();
}

/**
 * 设置某个元素的位置
 * @param {*} element 
 * @param {number | [number, number]} p1 
 * @param {number} p2 
 */
export const setElementPosition = (element, p1, p2) => {
    const positions = [undefined, undefined];
    return (() => {
        positions[0] = undefined;
        positions[1] = undefined;
        if (p1 && Array.isArray(p1)) {
            positions[0] = p1[0];
            positions[1] = p1[1];
        }
        else if (p1) {
            positions[0] = p1;
        }
        if (p2) {
            positions[1] = p2;
        }

        if (positions[0] !== undefined && positions[1] !== undefined) {
            element.move(positions[0], positions[1]);
        }

        else if (positions[0] !== undefined) {
            element.x(positions[0]);
        }

        else if (positions[1] !== undefined) {
            element.y(positions[1]);
        }

    })();
}

/** 导出当前svg */
export const exportSVG = () => {
    const blob = new Blob([svgString], { type: 'image/svg+xml;charset=utf-8' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'crane-copy.svg';
    a.click();
}